/*
 * @(#)Entry.java   13/08/20
 * 
 * Copyright (c) 2013 DieHard Development
 *
 * All rights reserved.
   Released under the BSD 3 clause license
Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

    Redistributions of source code must retain the above copyright notice, this 
    list of conditions and the following disclaimer. Redistributions in binary 
    form must reproduce the above copyright notice, this list of conditions and 
    the following disclaimer in the documentation and/or other materials 
    provided with the distribution. Neither the name of the DieHard Development 
    nor the names of its contributors may be used to endorse or promote products 
    derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 *
 *
 *
 */


package showtest;

//~--- JDK imports ------------------------------------------------------------

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author TJ
 */
@Entity
@Table(
    name = "ENTRY",
    catalog = "",
    schema = "APP"
)
@SequenceGenerator(
    name = "seq",
    initialValue = 1,
    allocationSize = 10
)
@NamedQueries( {
    @NamedQuery(
        name = "Entry.findAll",
        query = "SELECT e FROM Entry e"
    ) , @NamedQuery(
        name = "Entry.findByTruckid",
        query = "SELECT e FROM Entry e WHERE e.truckid = :truckid"
    ) , @NamedQuery(
        name = "Entry.findByTruckowner",
        query = "SELECT e FROM Entry e WHERE e.truckowner = :truckowner"
    ) , @NamedQuery(
        name = "Entry.findByTruckmake",
        query = "SELECT e FROM Entry e WHERE e.truckmake = :truckmake"
    ) , @NamedQuery(
        name = "Entry.findByTruckclass",
        query = "SELECT e FROM Entry e WHERE e.truckclass = :truckclass ORDER BY e.votes DESC"
    ) , @NamedQuery(
        name = "Entry.findByVotes",
        query = "SELECT e FROM Entry e WHERE e.votes = :votes"
    )
})
public class Entry implements Serializable {
    private static final long serialVersionUID = 1L;
    @Transient
    private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    @Id
    @GeneratedValue(
        strategy = GenerationType.SEQUENCE,
        generator = "seq"
    )
    @Basic(optional = false)
    @Column(
        name = "TRUCKID",
        nullable = false,
        updatable = false
    )
    private Integer truckid;
    @Column(
        name = "TRUCKOWNER",
        length = 100
    )
    private String truckowner;
    @Column(
        name = "TRUCKMAKE",
        length = 100
    )
    private String truckmake;
    @Column(
        name = "TRUCKCLASS",
        length = 50
    )
    private String truckclass;
    @Column(name = "VOTES")
    private Integer votes;

    /**
     * Constructs ...
     *
     */
    public Entry() {}

    /**
     * Constructs ...
     *
     *
     * @param truckid
     */
    public Entry(Integer truckid) {
        this.truckid = truckid;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public Integer getTruckid() {
        return truckid;
    }

    /**
     * Method description
     *
     *
     * @param truckid
     */
    public void setTruckid(Integer truckid) {
        Integer oldTruckid = this.truckid;

        this.truckid = truckid;
        changeSupport.firePropertyChange("truckid", oldTruckid, truckid);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getTruckowner() {
        return truckowner;
    }

    /**
     * Method description
     *
     *
     * @param truckowner
     */
    public void setTruckowner(String truckowner) {
        String oldTruckowner = this.truckowner;

        this.truckowner = truckowner;
        changeSupport.firePropertyChange("truckowner", oldTruckowner, truckowner);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getTruckmake() {
        return truckmake;
    }

    /**
     * Method description
     *
     *
     * @param truckmake
     */
    public void setTruckmake(String truckmake) {
        String oldTruckmake = this.truckmake;

        this.truckmake = truckmake;
        changeSupport.firePropertyChange("truckmake", oldTruckmake, truckmake);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public String getTruckclass() {
        return truckclass;
    }

    /**
     * Method description
     *
     *
     * @param truckclass
     */
    public void setTruckclass(String truckclass) {
        String oldTruckclass = this.truckclass;

        this.truckclass = truckclass;
        changeSupport.firePropertyChange("truckclass", oldTruckclass, truckclass);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public Integer getVotes() {
        return votes;
    }

    /**
     * Method description
     *
     *
     * @param votes
     */
    public void setVotes(Integer votes) {
        Integer oldVotes = this.votes;

        this.votes = votes;
        changeSupport.firePropertyChange("votes", oldVotes, votes);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    @Override
    public int hashCode() {
        int hash = 0;

        hash += ((truckid != null)
                 ? truckid.hashCode()
                 : 0);

        return hash;
    }

    /**
     * Method description
     *
     *
     * @param object
     *
     * @return
     */
    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Entry)) {
            return false;
        }

        Entry other = (Entry) object;

        if (((this.truckid == null) && (other.truckid != null))
                || ((this.truckid != null) &&!this.truckid.equals(other.truckid))) {
            return false;
        }

        return true;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    @Override
    public String toString() {
        return "showtest.Entry[ truckid=" + truckid + " ]";
    }

    /**
     * Method description
     *
     *
     * @param listener
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    /**
     * Method description
     *
     *
     * @param listener
     */
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}


//~ Formatted in DD Std on 13/08/20
